/**
 * @projectName leetode
 * @package cn.leetcode
 * @className cn.leetcode.t100
 * @copyright Copyright 2020 Thunisoft, Inc All rights reserved.
 */
package cn.leetcode;

/**
 * t100
 * @description
 * @author fei
 * @date 2025/9/10 16:27
 * @version 1.0
 */
public class t100 {
    public boolean isSameTree(TreeNode p, TreeNode q) {
        return compare(p, q);
    }

    public boolean compare(TreeNode p, TreeNode q) {
        if (p == null && q == null) {
            return true;
        }
        if (p != null && q == null) {
            return false;
        }
        if (p == null && q != null){
            return false;
        }
        if (p.val != q.val){
            return false;
        }
        return compare(p.left, q.left) && compare(p.right, q.right);
    }
}
